// component/cardTall/cardTall.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    data:{
      type: Object,
      // 数据类型
      value:{}
      // 数据值
    }
  },
  options: {
    styleIsolation: 'apply-shared'
  },
  /**
   * 组件的初始数据
   */
  data: {
    imgUrl:getApp().globalData.imgUrl,
    hotSelect: 0,
    titleData: [],
    contentData: [],
    navlist:[],
    spaceImg: '', // 全屋特惠空间展示图片
    navCur: '',
    picChamfer: "Y",
    textAlign: "left",
    textStyle: "normal"
  },
  attached: function(){
    let cardDTOList = this.properties.data.cardDTOList
    let titleData = [] // 标题数据
    let contentData = [] // 内容数据
    for (var i = 0; i< cardDTOList.length; i++) {
      // 标题数据整理
      let objTitle = {}
      if (cardDTOList[i].titleType == 'text') {
        objTitle.id = cardDTOList[i].id
        objTitle.subTitleSelectedBgColor = cardDTOList[i].subTitleSelectedBgColor
        objTitle.subTitleSelectedTextColor = cardDTOList[i].subTitleSelectedTextColor
        objTitle.subTitleText = cardDTOList[i].subTitleText
        objTitle.subTitleTextColor = cardDTOList[i].subTitleTextColor
        objTitle.titlePic = cardDTOList[i].titlePic
        objTitle.titleSelectedBgColor = cardDTOList[i].titleSelectedBgColor
        objTitle.titleSelectedPic = cardDTOList[i].titleSelectedPic
        objTitle.titleSelectedTextColor = cardDTOList[i].titleSelectedTextColor
        objTitle.titleText = cardDTOList[i].titleText
        objTitle.titleTextColor = cardDTOList[i].titleTextColor
        objTitle.titleType = cardDTOList[i].titleType
      }
      if (cardDTOList[i].titleType == 'picture') {
        objTitle.id = cardDTOList[i].id
        objTitle.titlePic = cardDTOList[i].titlePic
        objTitle.titleSelectedPic = cardDTOList[i].titleSelectedPic
        objTitle.titleType = cardDTOList[i].titleType
      }
      titleData.push(objTitle)
      this.setData({
        titleData: titleData,
        hotSelect: titleData[0].id
      })
      // console.log('titleData', this.data.titleData)
      // 内容数据结构调整  两行四个
      if (cardDTOList[i].layoutStyle == "towLineFour") {
        // 整体
        if (cardDTOList[i].layoutType == "whole") {
          let wholeObj = {}
          wholeObj.layoutStyle = cardDTOList[i].layoutStyle
          wholeObj.layoutType = cardDTOList[i].layoutType
          wholeObj.id = cardDTOList[i].id
          wholeObj.showMoreButton = cardDTOList[i].showMoreButton
          wholeObj.moreButtonTextColor = cardDTOList[i].moreButtonTextColor
          wholeObj.moreButtonFrameColor = cardDTOList[i].moreButtonFrameColor
          wholeObj.moreButtonLinkAppId = cardDTOList[i].moreButtonLinkAppId
          wholeObj.moreButtonLinkType = cardDTOList[i].moreButtonLinkType
          wholeObj.moreButtonLinkUrl = cardDTOList[i].moreButtonLinkUrl
          wholeObj.moreButtonResourceId = cardDTOList[i].moreButtonResourceId
          // 商品专栏
          if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'specialColumn') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.solrProductDtos.records
            // 秒杀，拼团，砍价
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'seckill') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.products
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'spellBuy') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.buySkuList
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'cutPrice') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.priceSkuList
          } else if(!cardDTOList[i].cardItemGroupDTOList[0].contentType) {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].cardItemDTOList
          }
          wholeObj.topData = wholeObj.cardData.slice(0, 1)
          wholeObj.cardData = wholeObj.cardData.slice(1, 4)
          wholeObj.linkType = cardDTOList[i].cardItemGroupDTOList[0].linkType
          wholeObj.linkUrl = cardDTOList[i].cardItemGroupDTOList[0].linkUrl
          wholeObj.linkAppId = cardDTOList[i].cardItemGroupDTOList[0].linkAppId
          wholeObj.linkResourceId = cardDTOList[i].cardItemGroupDTOList[0].linkResourceId
          wholeObj.contentType = cardDTOList[i].cardItemGroupDTOList[0].contentType
          contentData.push(wholeObj)
        }
        // 独立
        if (cardDTOList[i].layoutType == "independent") {
          let cardItemGroupDTOList = cardDTOList[i].cardItemGroupDTOList
          let independentObj = {}
          let independentData = []
          independentObj.layoutStyle = cardDTOList[i].layoutStyle
          independentObj.layoutType = cardDTOList[i].layoutType
          independentObj.id = cardDTOList[i].id
          independentObj.showMoreButton = cardDTOList[i].showMoreButton
          independentObj.moreButtonTextColor = cardDTOList[i].moreButtonTextColor
          independentObj.moreButtonFrameColor = cardDTOList[i].moreButtonFrameColor
          independentObj.moreButtonLinkAppId = cardDTOList[i].moreButtonLinkAppId
          independentObj.moreButtonLinkType = cardDTOList[i].moreButtonLinkType
          independentObj.moreButtonLinkUrl = cardDTOList[i].moreButtonLinkUrl
          independentObj.moreButtonResourceId = cardDTOList[i].moreButtonResourceId
          for (var k = 0; k < cardItemGroupDTOList.length; k++) {
            let newIndepObj = {}
            newIndepObj = cardItemGroupDTOList[k].cardItemDTOList[0]
            newIndepObj.linkType = cardItemGroupDTOList[k].linkType
            newIndepObj.linkUrl = cardItemGroupDTOList[k].linkUrl
            newIndepObj.linkAppId = cardItemGroupDTOList[k].linkAppId
            newIndepObj.linkResourceId = cardItemGroupDTOList[k].linkResourceId
            newIndepObj.contentType = cardItemGroupDTOList[k].contentType
            independentData.push(newIndepObj)
            independentObj.cardData = independentData
            // independentObj.topData = independentObj.cardData.slice(0, 1)
            // independentObj.cardData = independentObj.cardData.slice(1, 4)
          }
          contentData.push(independentObj)
        }
         // 一大三小 上下
      } else if (cardDTOList[i].layoutStyle == 'oneBigThreeSmall') {
        if (cardDTOList[i].layoutType == 'upAndDown') {
          let oneBigObj = {}
          let oneBigData = []
          oneBigObj.layoutStyle = cardDTOList[i].layoutStyle
          oneBigObj.layoutType = cardDTOList[i].layoutType
          oneBigObj.id = cardDTOList[i].id
          oneBigObj.showMoreButton = cardDTOList[i].showMoreButton
          oneBigObj.moreButtonTextColor = cardDTOList[i].moreButtonTextColor
          oneBigObj.moreButtonFrameColor = cardDTOList[i].moreButtonFrameColor
          oneBigObj.moreButtonLinkAppId = cardDTOList[i].moreButtonLinkAppId
          oneBigObj.moreButtonLinkType = cardDTOList[i].moreButtonLinkType
          oneBigObj.moreButtonLinkUrl = cardDTOList[i].moreButtonLinkUrl
          oneBigObj.moreButtonResourceId = cardDTOList[i].moreButtonResourceId
          oneBigData = cardDTOList[i].cardItemGroupDTOList[0].cardItemDTOList
          let downData = []
          // 商品专栏
          if (cardDTOList[i].cardItemGroupDTOList[1].contentType == 'specialColumn') {
            downData = cardDTOList[i].cardItemGroupDTOList[1].contentData.solrProductDtos.records
            // 秒杀，拼团，砍价
          } else if (cardDTOList[i].cardItemGroupDTOList[1].contentType == 'seckill') {
            downData = cardDTOList[i].cardItemGroupDTOList[1].contentData.products
          } else if (cardDTOList[i].cardItemGroupDTOList[1].contentType == 'spellBuy') {
            downData = cardDTOList[i].cardItemGroupDTOList[1].contentData.buySkuList
          } else if (cardDTOList[i].cardItemGroupDTOList[1].contentType == 'cutPrice') {
            downData = cardDTOList[i].cardItemGroupDTOList[1].contentData.priceSkuList
          } else if(!cardDTOList[i].cardItemGroupDTOList[1].contentType) {
            downData = cardDTOList[i].cardItemGroupDTOList[1].cardItemDTOList
          }
          oneBigData = oneBigData.concat(downData)
          for (var j = 0; j < oneBigData.length; j++) {
            if (j == 0) {
              oneBigData[j].linkType = cardDTOList[i].cardItemGroupDTOList[0].linkType
              oneBigData[j].linkUrl = cardDTOList[i].cardItemGroupDTOList[0].linkUrl
              oneBigData[j].linkAppId = cardDTOList[i].cardItemGroupDTOList[0].linkAppId
              oneBigData[j].linkResourceId = cardDTOList[i].cardItemGroupDTOList[0].linkResourceId
              oneBigData[j].contentType = cardDTOList[i].cardItemGroupDTOList[0].contentType
            } else {
              oneBigData[j].linkType = cardDTOList[i].cardItemGroupDTOList[1].linkType
              oneBigData[j].linkUrl = cardDTOList[i].cardItemGroupDTOList[1].linkUrl
              oneBigData[j].linkAppId = cardDTOList[i].cardItemGroupDTOList[1].linkAppId
              oneBigData[j].linkResourceId = cardDTOList[i].cardItemGroupDTOList[1].linkResourceId
              oneBigData[j].contentType = cardDTOList[i].cardItemGroupDTOList[1].contentType
            }
          }
          oneBigObj.cardData = oneBigData
          oneBigObj.topData = oneBigObj.cardData.slice(0, 1)
          oneBigObj.cardData = oneBigObj.cardData.slice(1, 4)
          contentData.push(oneBigObj)
        }
        // 整体
        if (cardDTOList[i].layoutType == "whole") {
          let wholeObj = {}
          wholeObj.layoutStyle = cardDTOList[i].layoutStyle
          wholeObj.layoutType = cardDTOList[i].layoutType
          wholeObj.id = cardDTOList[i].id
          wholeObj.showMoreButton = cardDTOList[i].showMoreButton
          wholeObj.moreButtonTextColor = cardDTOList[i].moreButtonTextColor
          wholeObj.moreButtonFrameColor = cardDTOList[i].moreButtonFrameColor
          wholeObj.moreButtonLinkAppId = cardDTOList[i].moreButtonLinkAppId
          wholeObj.moreButtonLinkType = cardDTOList[i].moreButtonLinkType
          wholeObj.moreButtonLinkUrl = cardDTOList[i].moreButtonLinkUrl
          wholeObj.moreButtonResourceId = cardDTOList[i].moreButtonResourceId
          // 商品专栏
          if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'specialColumn') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.solrProductDtos.records
            // 秒杀，拼团，砍价
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'seckill') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.products
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'spellBuy') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.buySkuList
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'cutPrice') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.priceSkuList
          } else if(!cardDTOList[i].cardItemGroupDTOList[0].contentType) {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].cardItemDTOList
          }
          wholeObj.topData = wholeObj.cardData.slice(0, 1)
          wholeObj.cardData = wholeObj.cardData.slice(1, 4)
          wholeObj.linkType = cardDTOList[i].cardItemGroupDTOList[0].linkType
          wholeObj.linkUrl = cardDTOList[i].cardItemGroupDTOList[0].linkUrl
          wholeObj.linkAppId = cardDTOList[i].cardItemGroupDTOList[0].linkAppId
          wholeObj.linkResourceId = cardDTOList[i].cardItemGroupDTOList[0].linkResourceId
          wholeObj.contentType = cardDTOList[i].cardItemGroupDTOList[0].contentType
          console.log('wholeObj.cardData',  wholeObj.topData)
          contentData.push(wholeObj)
          console.log('一大三小整体', contentData)
        }
        // 独立
        if (cardDTOList[i].layoutType == "independent") {
          let cardItemGroupDTOList = cardDTOList[i].cardItemGroupDTOList
          let independentObj = {}
          let independentData = []
          independentObj.layoutStyle = cardDTOList[i].layoutStyle
          independentObj.layoutType = cardDTOList[i].layoutType
          independentObj.id = cardDTOList[i].id
          independentObj.showMoreButton = cardDTOList[i].showMoreButton
          independentObj.moreButtonTextColor = cardDTOList[i].moreButtonTextColor
          independentObj.moreButtonFrameColor = cardDTOList[i].moreButtonFrameColor
          independentObj.moreButtonLinkAppId = cardDTOList[i].moreButtonLinkAppId
          independentObj.moreButtonLinkType = cardDTOList[i].moreButtonLinkType
          independentObj.moreButtonLinkUrl = cardDTOList[i].moreButtonLinkUrl
          independentObj.moreButtonResourceId = cardDTOList[i].moreButtonResourceId
          for (var l = 0; l < cardItemGroupDTOList.length; l++) {
            let newIndepObj = {}
            newIndepObj = cardItemGroupDTOList[l].cardItemDTOList[0]
            newIndepObj.linkType = cardItemGroupDTOList[l].linkType
            newIndepObj.linkUrl = cardItemGroupDTOList[l].linkUrl
            newIndepObj.linkAppId = cardItemGroupDTOList[l].linkAppId
            newIndepObj.linkResourceId = cardItemGroupDTOList[l].linkResourceId
            newIndepObj.contentType = cardItemGroupDTOList[l].contentType
            independentData.push(newIndepObj)
            independentObj.cardData = independentData
            independentObj.topData = independentObj.cardData.slice(0, 1)
            independentObj.cardData = independentObj.cardData.slice(1, 4)
          }
          contentData.push(independentObj)
        }
        // console.log('contentData', contentData)
        // 全屋专区
      } else if (cardDTOList[i].layoutStyle == 'wholeHousePurchase' && cardDTOList[i].wholeHouseBuy) {
        let wholeHouseObj = {}
        wholeHouseObj.layoutStyle = cardDTOList[i].layoutStyle
        wholeHouseObj.id = cardDTOList[i].id
        // wholeHouseObj.showMoreButton = cardDTOList[i].showMoreButton
        // wholeHouseObj.moreButtonLinkAppId = cardDTOList[i].moreButtonLinkAppId
        // wholeHouseObj.moreButtonLinkType = cardDTOList[i].moreButtonLinkType
        // wholeHouseObj.moreButtonLinkUrl = cardDTOList[i].moreButtonLinkUrl
        // wholeHouseObj.moreButtonResourceId = cardDTOList[i].moreButtonResourceId
        wholeHouseObj.spaceInfo = cardDTOList[i].wholeHouseBuy.spaceInfo
        wholeHouseObj.productInfo = cardDTOList[i].wholeHouseBuy.productInfo
        wholeHouseObj.activityId = cardDTOList[i].wholeHouseBuy.activityId
        wholeHouseObj.mealId = cardDTOList[i].wholeHouseBuy.mealId
        // wholeHouseObj.topData =  wholeHouseObj.productInfo.slice(0, 1)
        // wholeHouseObj.cardData =  wholeHouseObj.productInfo.slice(1, 4)
        contentData.push(wholeHouseObj)
        this.setData({
          navlist:  wholeHouseObj.spaceInfo,
          spaceImg: wholeHouseObj.spaceInfo[0].pics[0].picturePath,
          navCur: wholeHouseObj.spaceInfo[0].pics[0].id
        })
      }
    }
    this.setData({
      contentData: contentData
    })
  },
  ready: function() {
    this.setData({
      picChamfer: this.properties.data.picChamfer,
      textAlign: this.properties.data.textAlign,
      textStyle: this.properties.data.textStyle
    })
  },
  /**
   * 组件的方法列表
   */
  methods: {
    tabHot(data) {
      const id = data.currentTarget.dataset.data.id
      this.setData({
        hotSelect: id
      })
    },
     // 全屋购分类
  navSelect(e) {
    this.setData({
      navCur: e.currentTarget.dataset.id,
     })
     let navlist = this.data.navlist
    for(var i = 0, len = navlist.length; i < len; i++) {
      if (e.currentTarget.dataset.id == navlist[i].pics[0].id) {
        this.setData({
          spaceImg: navlist[i].pics[0].picturePath,
         })
      }
    }
  },
  // 页面跳转
  linkJump(listItem) {
    let linkType = listItem.currentTarget.dataset.listitem.linkType
    let linkAppId =  listItem.currentTarget.dataset.listitem.linkAppId
    // let linkResourceId = listItem.currentTarget.dataset.listitem.linkResourceId
    let linkUrl = listItem.currentTarget.dataset.listitem.linkUrl
    let contentType = listItem.currentTarget.dataset.listitem.contentType
    if (linkType == 'otherMiniProgram') { // 其他小程序跳转
      this.goMeita(linkAppId)
    } else if (linkType == 'miniPage') {
      wx.navigateTo({
        url: linkUrl
      })
    } else if(linkType == 'h5' && linkUrl!== '/packagBuy/pages/found/crmweb/index') {
      wx.navigateTo({
        url: '/packagBuy/pages/marketing/poster/posterh5/posterh5?h5Url=' + linkUrl
      })
    } else if(linkUrl == '/packagBuy/pages/found/crmweb/index') {
      wx.navigateTo({
        url: '/packagBuy/pages/found/crmweb/index'
      })
    } else {
     if (contentType == 'selectedCase') {
      this.goMeita(linkAppId)
     } else if(contentType == 'articleType') {
      wx.navigateTo({
        url: '/packagBuy/pages/found/encyclopedia/encyclopedia'
      })
     }
    }
  },
  goSeeMore(listItem) {
    let linkType = listItem.currentTarget.dataset.listitem.moreButtonLinkType
    let linkAppId =  listItem.currentTarget.dataset.listitem.moreButtonLinkAppId
    // let linkResourceId = listItem.currentTarget.dataset.listitem.linkResourceId
    let linkUrl = listItem.currentTarget.dataset.listitem.moreButtonLinkUrl
    let contentType = listItem.currentTarget.dataset.listitem.contentType
    if (linkType == 'otherMiniProgram') { // 其他小程序跳转
      this.goMeita(linkAppId)
    } else if (linkType == 'miniPage') {
      wx.navigateTo({
        url: linkUrl
      })
    } else if(linkType == 'h5' && linkUrl!== '/packagBuy/pages/found/crmweb/index') {
      wx.navigateTo({
        url: '/packagBuy/pages/marketing/poster/posterh5/posterh5?h5Url=' + linkUrl
      })
    } else if(linkUrl == '/packagBuy/pages/found/crmweb/index') {
      wx.navigateTo({
        url: '/packagBuy/pages/found/crmweb/index'
      })
    } else {
     if (contentType == 'selectedCase') {
      this.goMeita(linkAppId)
     } else if(contentType == 'articleType') {
      wx.navigateTo({
        url: '/packagBuy/pages/found/encyclopedia/encyclopedia'
      })
     }
    }
  },
  // 美搭小程序跳转
    goMeita(linkAppId) {
      wx.navigateToMiniProgram({
        appId: linkAppId,//小程序appid
        path: '',//跳转关联小程序app.json配置里面的地址
        extraData: {
          foo: 'bar'
        },
      //**重点**要打开的小程序版本，有效值 develop（开发版），trial（体验版），release（正式版）
        envVersion: 'release',
        success(res) {
          // 打开成功
        }
      })
    },
    gowholehoseDetail(e) {
    // this.getLogin((re)=>{
    //   if(re){
      let activityId = e.currentTarget.dataset.item.activityId
      let id = e.currentTarget.dataset.item.mealId
      let option = {
        activityId: activityId,
        id: id
      }
      wx.navigateTo({
        url: '/packagBuy/pages/marketing/wholehouse/details/details?option=' + JSON.stringify(option),
      })
  //   }
  // })
    },
    goWholehouse() {
      // this.getLogin((re)=>{
      //   if(re){
        wx.navigateTo({
          url: '/packagBuy/pages/marketing/wholehouse/index/index'
        })
    //   }
    // })
    },
  }
})
